package com.cong.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author cong
 * <p>
 * created on 2021/4/20 下午4:55
 */
public class ChannelDemo02 {
    public static void main(String[] args) throws IOException {
        String s = "ccccccccccccc";
        File file = new File("/data/cong/channel1.txt");
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
        channel.read(byteBuffer);
        byte[] b = byteBuffer.array();
        System.out.println(new String(b));
        fis.close();
    }
}
